// components/shop-list/index.js
const app = getApp()

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    pageFlag: {
      type: Number,
      observer(val){
        console.log(val)
        this.loadMore()
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    noMore:false,
    loading:true
  },

  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      this.no = 1;
      var params = {};
      params.no = this.no;
      params.size = 10;
      params.auditState = "checked";
      var func=this.loadFinsh.bind(this);
      app.dataRequest("/rest/shop/search.htm", params,this,"shops",func);
    },
    loadFinsh(){
      self.triggerEvent('loadingChange', {loading:false});
      this.setData({loading:false});

    },
    loadMore() {
      this.setData({
        page: this.data.page + 1
      })
      console.info(this.totalPage);
      if (this.no < this.totalPage) {
        this.no = this.no + 1;
        this.setData({noMore:false});
        var params = {};
        params.no = this.no;
        params.size = 10;
        params.auditState = "checked";
        app.loadMore("/rest/shop/search.htm", params,this,"shops");
  
      }else{
        this.setData({noMore:true});
      }
    },
  },
  lifetimes: {

    created:function(){
     
    },
    attached: function () {
      // 在组件实例进入页面节点树时执行

      self = this;
      this.init();
    },
    show: function() {
      // 页面被展示
     
    },
    hide: function() {
      // 页面被隐藏
    },
    resize: function(size) {
      // 页面尺寸变化
    }
  }
})
